import Vue from 'vue'
import Vuex from 'vuex'
import {login,register} from '../api' 
import getAuth from './getAuth'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: {}
  },
  mutations: {},
  actions: {
    async userlogin({ commit }, payload) {
      let res = await login(payload)
      if (res.data.code === "000") {
        
        let token = res.data.token
        localStorage.setItem('token', token)
        let userInfos = res.data.data.typename
        // console.log(res.data.data);
        
        localStorage.setItem('user',userInfos)
        commit('getAuth/filterAuth', userInfos, { root: true })
      }else{
        alert(res.data.msg)
      }
    },

    async resgister({ commit }, payload) {
      register(payload)
    }
  },
  modules: {
    getAuth
  }
})
